package org.jhotdraw.app.action.file;

import java.io.File;
import java.net.URI;

import javax.swing.JOptionPane;

import org.jhotdraw.app.View;
import org.jhotdraw.gui.URIChooser;

public aspect Overwrite {
	pointcut askOverwrite(View v, URI u, URIChooser uc):
	args(v, u, uc) && call (protected void SaveFileAction.saveViewToURI(View, URI, URIChooser));

	void around(View v, URI u, URIChooser uc): askOverwrite(v,u,uc){
		File arquivo = new File(u);
		if (arquivo.exists()) {
			int resultado = JOptionPane.showConfirmDialog(null, "Deseja sobreescrever o arquivo?", "Alerta", JOptionPane.YES_NO_OPTION);
			if (resultado == 1) {
				proceed(v, u, uc);
			}
		} else {
			proceed(v, u, uc);
		}
	}
}
